package com.heqiang.spring.factory;

import com.heqiang.spring.BeansException;
import com.heqiang.spring.config.BeanDefinition;

public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory {

    @Override
    protected Object createBean(String name, BeanDefinition beanDefinition) throws BeansException {
        Object bean = null;
        try {
             bean = beanDefinition.getBeanClass().newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new BeansException("Instantiation of bean failed", e);
        }
        //新增一个bean到单例中
        addSingleton(name,bean);
        return bean;
    }
}
